package main

import ("http"; "fmt"; "io"; "template"; "time")

func HelloServer(c *http.Conn, req *http.Request) {
    fmt.Println( "oh, I have been called, me dearies!" )
    io.WriteString(c, "hello, world!\n");
    }

const Thingy = `here we go round the {now} mulberry bush, again.`

func TemplateServer( c *http.Conn, req *http.Request ) {
    now := time.LocalTime().Format( time.UnixDate )
    t := template.MustParse( Thingy, make(map[string]func(io.Writer, interface{}, string)))
    t.Execute( map[string]string{"now": now}, c )
}

func main() {
    fmt.Println( "here we go round the mulberry bush." )
    root, prefix := "/home/chris/Server/files", ""
    http.Handle( "/", http.FileServer( root, prefix ) )
    http.Handle( "/example", http.HandlerFunc( TemplateServer ) )
    http.Handle( "/hello", http.HandlerFunc( HelloServer ) )
    err := http.ListenAndServe(":8081", nil);
    if err != nil { panic( "ListenAndServe: " + err.String() ) }
}

